% !Mode:: "TeX:UTF-8"
\section{图像复原}

\subsection{问题}
假设有模糊函数如：
\begin{equation}
H(u,v)=\frac{T}{\pi(ua+vb)}\sin\left[ \pi(ua+vb)\right] e^{-j\pi(ua+vb)}
\end{equation}
\begin{enumerate}
 \item 实现该模糊滤波器。其中$a=b=0.1\quad T=1$
 \item 对模糊后的图像加入$\mu=0\,,\sigma^2=650$的高斯噪声
 \item 用逆滤波器和维纳滤波器复原加入噪声和没加入噪声的模糊图像
 \item 用不同的$\sigma$重复上述复原过程
\end{enumerate}

\subsection[背景原理]{背景原理}
\subsubsection{理想逆滤波器复原的缺陷和改进}
\begin{cdefi}
设模糊函数为$H(u,v)$，图像的傅里叶变换为$F(u,v)$，则有模糊后的图像$F'(u,v)=H(u,v)F(u,v)$。自然的有复原函数 $H^{-1}(u,v)=\frac{1}{H(u,v)}$,称为{\bf 理想逆滤波器}。有$F(u,v)=H^{-1}(u,v)F'(u,v)=\frac{F'(u,v)}{H(u,v)}$
\end{cdefi}
但是由于实际环境中的种种特点，理想逆滤波器效果不理想，往往需要加入限定条件。比如：
\begin{equation}
H^{-1}(u,v)=\left\{
\begin{array}{l}
\frac{1}{H(u,v)} \quad |H(u,v)|\ge D \\
K \quad |H(u,v)| < D \\
\end{array}
\right.
\end{equation}
其中$D$和$K$都是很小的整实数。
\subsubsection[维纳滤波器]{维纳滤波器}
\begin{cdefi}
设模糊函数为$H(u,v)$,定义：
\begin{equation}
W(u,v)=\frac{1}{H(u,v)}\times \frac{|H(u,v))|^2}{|H(u,v)|^2+s[S_n(u,v)/S_f(u,v)]}
\end{equation}
$S_n(u,v)$为噪声频谱，$S_f(u,v)$为原图像频谱。当$s=1$时，称为{\bf 维纳滤波器}。 当$S_n(u,v)=0$维纳滤波器退化为理想逆滤波器。

实际中，$S_n(u,v)$和$S_f(u,v)$都是未知的，用下式来近似表示。
\begin{equation}
W(u,v)=\frac{|H(u,v)|^2}{H(u,v)(|H(u,v)|^2+K)}
\end{equation}
其中$K$为常数,当$K=0$时，维纳滤波器退化为理想逆滤波器。
\end{cdefi}
\subsection{程序代码说明}

程序代码在文件 src/q5\_restoration/q5.py 中。

{\bf inverse\_restoration}为逆滤波器

{\bf wiener}为维纳滤波器

\subsection{实验结果与分析}
\subsubsection{输出结果}
\begin{longtable}{ll}
\caption{图像复原} \\
%\toprule
%\multicolumn{2}{c}{图像复原} \\
%\midrule
%\endfirsthead
%\midrule
%\multicolumn{2}{c}{图像复原} \\
%\midrule
\endhead
%\midrule
\multicolumn{2}{r}{接下页\dots} \\
\endfoot
\endlastfoot
\hline
\begin{tabular}{l}
原图像  \\
\includegraphics[height=4.25cm]{../output/Q5_orig.jpg}
\end{tabular}
&
\begin{tabular}{l}
原图像频谱 \\
\includegraphics[height=4.25cm]{../output/Q5_fft.jpg}
\end{tabular}
\\
\hline
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{tabular}{l}
模糊图像  \\
\includegraphics[height=4.25cm]{../output/Q5_blur.jpg}
\end{tabular}
&
\begin{tabular}{l}
模糊图像频谱 \\
\includegraphics[height=4.25cm]{../output/Q5_fft_of_inverse_for_blur.jpg}
\end{tabular}
\\
\hline
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{tabular}{l}
模糊图像的逆滤波器复原 \\
\includegraphics[height=4.25cm]{../output/Q5_inverse_for_blur.jpg}
\end{tabular}
&
\\
\hline
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{tabular}{l}
模糊加噪声图像$\sigma^2=650$ \\
\includegraphics[height=4.25cm]{../output/Q5_blur_gaus_noise_650.jpg}
\end{tabular}
&
\begin{tabular}{l}
模糊加噪声图像频谱$\sigma^2=650$ \\
\includegraphics[height=4.25cm]{../output/Q5_fft_of_inverse_for_blur_noise_650.jpg}
\end{tabular}
\\
\hline
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{tabular}{l}
模糊加噪声图像$\sigma^2=4$ \\
\includegraphics[height=4.25cm]{../output/Q5_blur_gaus_noise_4.jpg}
\end{tabular}
&
\begin{tabular}{l}
模糊加噪声图像频谱$\sigma^2=4$ \\
\includegraphics[height=4.25cm]{../output/Q5_fft_of_inverse_for_blur_noise_4.jpg}
\end{tabular}
\\
\hline
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{tabular}{l}
模糊加噪声图像逆滤波器复原$\sigma^2=650$  \\
\includegraphics[height=4.25cm]{../output/Q5_inverse_for_blur_noise_650.jpg}
\end{tabular}
&
\begin{tabular}{l}
模糊加噪声图像逆滤波器复原$\sigma^2=4$ \\
\includegraphics[height=4.25cm]{../output/Q5_inverse_for_blur_noise_4.jpg}
\end{tabular}\\
%hline
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{tabular}{l}
维纳滤波器对模糊加噪声图像的复原$\sigma^2=650$ \\
\includegraphics[height=4.25cm]{../output/Q5_wiener_restoration_for_blur_noise_650_K=0.0100.jpg}
\end{tabular}
&
\begin{tabular}{l}
维纳滤波器对模糊加噪声图像的复原$\sigma^2=4$\\
\includegraphics[height=4.25cm]{../output/Q5_wiener_restoration_for_blur_noise_4_K=0.0010.jpg}
\end{tabular}\\
\bottomrule
\end{longtable} 
\subsubsection{分析}
由于没有噪声时，维纳滤波器退化为逆滤波器，所以没有噪声的模糊图像只使用逆滤波器进行复原，其结果比较接近原图像。

当噪声还不是很大时($\sigma^2=4$），逆滤波器的复原质量大大下降，不过图像内容仍然可以辨识。维纳滤波器结果接近原图像。

当噪声还很大时($\sigma^2=650$），逆滤波器的复原结果不可用，图像内容完全丢失。维纳滤波器虽然也大大下降，但原图像的信息仍然可以辨识出相当部分。